package com.juneng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.Condition;
import com.juneng.utils.BeanCopyUtils;
import com.juneng.entity.UserAccount;
import com.juneng.mapper.UserAccountMapper;
import com.juneng.service.IUserAccountService;
import com.juneng.dto.UserAccountDto;
import com.juneng.dto.UserAccountQueryDto;
import com.juneng.vo.UserAccountVo;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;
import java.util.List;
/**
 * 用户账号 服务实现类
 *
 * @author zds
 * @since 2021-07-08
 */
@Service
@AllArgsConstructor
public class UserAccountServiceImpl implements IUserAccountService {

    protected UserAccountMapper userAccountMapper;

    @Override
    public IPage<UserAccountVo> page(UserAccountQueryDto dto) {
        IPage<UserAccountVo> page = Condition.getPage(dto);
        return userAccountMapper.page(page,dto);
    }

    @Override
    public List<UserAccount> list(UserAccountQueryDto dto) {
        QueryWrapper<UserAccount> queryWrapper = new QueryWrapper<>(BeanCopyUtils.copy(dto,UserAccount.class));
        return userAccountMapper.selectList(queryWrapper);
    }

    @Override
    public Integer save(UserAccountDto dto) {
        return userAccountMapper.insert(BeanCopyUtils.copy(dto,UserAccount.class));
    }

    @Override
    public Integer updateById(UserAccountDto dto) {
        return userAccountMapper.updateById(BeanCopyUtils.copy(dto,UserAccount.class));
    }

    @Override
    public Integer deleteLogic(List<Integer> toIntList) {
        return userAccountMapper.deleteBatchIds(toIntList);
    }

    @Override
    public UserAccount getById(Long id) {
        return userAccountMapper.selectById(id);
    }

    /**
     * 查询用户账号
     * @param userName
     * @return
     */
    @Override
    public UserAccount getUserAccount(String userName) {
        UserAccount userAccount = userAccountMapper.selectOne(new LambdaQueryWrapper<UserAccount>().eq(UserAccount::getAccountName, userName));
        return userAccount;
    }
}
